package reflect;

import java.util.Scanner;

/**
 * 使用反射机制实例化对象
 */
public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        /*反射机制实例化对象
        * 1:加载要实例化对象的类的类对象
            2:利用类对象来实例化*/
//        Class cls = Class.forName("reflect.Person");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个类名:");
        String name = scanner.nextLine();
        Class cls = Class.forName(name);
        Object obj = cls.newInstance();//利用公开的无参构造器实例化对象
        System.out.println(obj);
    }
}
